package com.example.community.uitls;

import org.springframework.stereotype.Component;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: CookieUtil
 * @Description:
 * @Author
 * @Date 2022-03-18
 * @Version 1.0
 */
public class CookieUtil {

    public static String getValue(HttpServletRequest request,String name){
        if (request==null || name==null){
            throw new IllegalArgumentException();
        }

        Cookie[] cookies = request.getCookies();
        if (cookies!=null){
            for (Cookie cookie:cookies){
                if (cookie.getName().equals(name)){
                    return cookie.getValue();
                }
            }
        }
        return null;
    }
}
